package com.jinkaimen.goodcash.ui.activity;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.retrofit.RequestUtils;
import com.ht.baselibs.retrofit.bean.RequestParam;
import com.ht.baselibs.retrofit.converter.fastjson.FastJsonConverterFactory;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.DateUtils;
import com.ht.baselibs.utils.DeviceUtils;
import com.ht.baselibs.utils.LogUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.ht.baselibs.utils.UIUtils;
import com.jinkaimen.goodcash.R;
import com.jinkaimen.goodcash.api.FileApi;
import com.jinkaimen.goodcash.bean.AuUserBean;
import com.jinkaimen.goodcash.bean.BizShopBean;
import com.jinkaimen.goodcash.bean.SearchShopBean;
import com.jinkaimen.goodcash.constant.HttpConfig;
import com.jinkaimen.goodcash.manager.ApiManager;
import com.jinkaimen.goodcash.thread.CompressPhotoThread;
import com.jinkaimen.goodcash.ui.weiget.dialog.CustomPopwindow;
import com.jinkaimen.goodcash.ui.weiget.dialog.DialogUtils;
import com.jinkaimen.goodcash.utils.PermissionUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;

public class IdentificationShopStep3Activity extends BaseActivity {

//    private static final int REQUEST_CODE_TAKE_PHOTO_ID_CARD = 0;//法人身份证正面
//    private static final int REQUEST_CODE_TAKE_PHOTO_BANK_CARD = 1;
//    private static final int REQUEST_CODE_TAKE_PHOTO_PAGE = 2;
//    private static final int REQUEST_CODE_TAKE_PHOTO_BANK = 3;//新增
//
//    private static final int REQUEST_CODE_TAKE_PHOTO_ID_CARD_PHOTO = 4;//法人身份证正面
//    private static final int REQUEST_CODE_TAKE_PHOTO_BANK_CARD_PHOTO = 5;
//    private static final int REQUEST_CODE_TAKE_PHOTO_PAGE_PHOTO = 6;
//    private static final int REQUEST_CODE_TAKE_PHOTO_BANK_PHOTO = 7;//新增

    private static final int MY_PERMISSIONS_REQUEST_CALL_CAMERA = 0;
    private static final int MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD = 1;

    private static final String TAKE_PHOTO_PATH_ID_CARD = "ht/jkm/photo/IDCARDF.jpg";//法人身份证正面
    private static final String TAKE_PHOTO_PATH_BANK_CARD = "ht/jkm/photo/IDCARDB.jpg";//背面照
    private static final String TAKE_PHOTO_PATH_CARD = "ht/jkm/photo/CONTRACT.jpg";//结算卡
    private static final String TAKE_PHOTO_PATH_PAGE = "ht/jkm/photo/CARDB.jpg";//合同

    //    private TextView mStep1View;
//    private TextView mStep2View;
//    private TextView mStep3View;
    private EditText mNameView;
    private EditText mTelView;
    private ImageView mIdCardView;
    private ImageView mBankCardView;
    private ImageView mPageView;
    private long mShopId;
    private long mUserId;
    private boolean canEdit;
    private TextView mNextButton;
    private boolean mIsPublic;
    private ImageView mBankCardViewNew;
    private boolean photo1;
    private boolean photo2;
    private boolean photo3;
    private boolean photo4;

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        if (canEdit) {
            mTitleBarView.setLeftBtnIcon(View.GONE)
                    .setTitleText("填写商铺资料").addActions(
                    new TitleBarView.Action("上一步") {
                        @Override
                        public void performAction(View view) {
                            Bundle bundle = new Bundle();
                            bundle.putLong("report_shop_id", mShopId);
                            bundle.putBoolean("canEdit", true);
                            bundle.putLong("report_account_id", mUserId);
                            ActivityUtils.startActivityAndFinish(IdentificationShopStep3Activity.this, IdentificationShopStep2Activity.class, bundle);
                        }
                    }
            );
        } else {
            mTitleBarView.setTitleText("填写店铺资料").addActions(
                    new TitleBarView.Action("下一步") {
                        @Override
                        public void performAction(View view) {
                            Bundle bundle = new Bundle();
                            bundle.putBoolean("canEdit", canEdit);
                            bundle.putLong("report_account_id", mUserId);
                            bundle.putLong("report_shop_id", mShopId);
                            ActivityUtils.startActivityAndFinish(IdentificationShopStep3Activity.this, IdentificationShopStep4Activity.class, bundle);
                        }
                    }
            );
        }
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        mShopId = callIntent.getLongExtra("report_shop_id", 0);
        mUserId = callIntent.getLongExtra("report_account_id", 0);
        canEdit = callIntent.getBooleanExtra("canEdit", true);
        mIsPublic = callIntent.getBooleanExtra("isPublic", false);
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_identification_shop_step3;
    }

    @Override
    protected void initChildView() {
        mNameView = (EditText) findViewById(R.id.et_activity_identification_shop_step3_name);
        mTelView = (EditText) findViewById(R.id.et_activity_identification_shop_step3_tel);

        mIdCardView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step3_id_card);
        mBankCardView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step3_bank_card);
        mBankCardViewNew = (ImageView) findViewById(R.id.iv_activity_identification_shop_step3_page_new);
        mPageView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step3_page);
        mNextButton = (TextView) findViewById(R.id.btn_activity_identification_shop);

        DoCanEdit(canEdit);
    }

    private void DoCanEdit(Boolean canEdit) {
        mNameView.setFocusable(canEdit);
        mNameView.setFocusableInTouchMode(canEdit);

        mTelView.setFocusable(canEdit);
        mTelView.setFocusableInTouchMode(canEdit);
        mNextButton.setVisibility(canEdit ? View.VISIBLE : View.GONE);
    }

    @Override
    protected void initChildData() {
        doBackPic();
        showLoadingDialog();
        ApiManager.getApi().searchShopInfo(
                "INV_HSY001010",
                mUserId
        ).enqueue(new NetCallBack<SearchShopBean>() {
            @Override
            protected void onSuccess(Call<SearchShopBean> call, Response<SearchShopBean> response) {
                BizShopBean appBizShop = new BizShopBean();
                try {
                    appBizShop = response.body().appBizShop;
                } catch (Exception e) {
                    e.printStackTrace();
                }

                DoBackfillInfo(appBizShop);

            }

            @Override
            protected boolean isNullNeedCallback() {
                return true;
            }

            @Override
            protected void hiddenProgress() {
                hideLodingDialog();
            }
        });

    }

    private void doBackPic() {
        String path = SharedPreferencesUtils.getString("request_code_take_photo_id_card_photo" + mShopId, "");
        if (!TextUtils.isEmpty(path)) {
            photo1 = true;
            Glide.with(this)//
                    .load(path)//
                    .skipMemoryCache(true)//
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .into(mIdCardView);
        }
        String path1 = SharedPreferencesUtils.getString("request_code_take_photo_bank_card_photo" + mShopId, "");
        if (!TextUtils.isEmpty(path1)) {
            photo2 = true;
            Glide.with(this)//
                    .load(path1)//
                    .skipMemoryCache(true)//
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .into(mBankCardView);
        }
        String path2 = SharedPreferencesUtils.getString("request_code_take_photo_bank_photo" + mShopId, "");
        if (!TextUtils.isEmpty(path2)) {
            photo3 = true;
            Glide.with(this)//
                    .load(path2)//
                    .skipMemoryCache(true)//
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .into(mPageView);
        }
        String path3 = SharedPreferencesUtils.getString("request_code_take_photo_page_photo" + mShopId, "");
        if (!TextUtils.isEmpty(path3)) {
            photo4 = true;
            Glide.with(this)//
                    .load(path3)//
                    .skipMemoryCache(true)//
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .into(mBankCardViewNew);
        }
    }

    private void DoBackfillInfo(BizShopBean appBizShop) {
        String name = appBizShop.contactName;
        String num = appBizShop.contactCellphone;
        mNameView.setText(name);
        mTelView.setText(num);
    }

    @Override
    protected void setChildViewListener() {
        mNextButton.setOnClickListener(this);
        mIdCardView.setOnClickListener(this);
        mBankCardView.setOnClickListener(this);
        mBankCardViewNew.setOnClickListener(this);
        mPageView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_activity_identification_shop:
                String name = mNameView.getText().toString();
                String tel = mTelView.getText().toString();
                if (!photo1) {
                    UIUtils.showToast("请上传法人身份证正面照");
                    return;
                }
                if (!photo2) {
                    UIUtils.showToast("请上传法人身份证背面照");
                    return;
                }
                if (!photo3) {
                    UIUtils.showToast("请上传结算卡正面照");
                    return;
                }
                if (!photo4) {
                    UIUtils.showToast("请上传合同");
                    return;
                }

                if (TextUtils.isEmpty(name)) {
                    UIUtils.showToast("请输入联系人姓名");
                    return;
                }

                if (TextUtils.isEmpty(tel)) {
                    UIUtils.showToast("请输入联系人电话");
                    return;
                }

                if (tel.length() != 11) {
                    UIUtils.showToast("请输入正确的手机号");
                    return;
                }

                showLoadingDialog();
                HashMap<String, Object> requestDataMap = new HashMap<>();
                requestDataMap.put("id", mShopId);
                requestDataMap.put("uid", mUserId);
                requestDataMap.put("contactName", name);
                requestDataMap.put("contactCellphone", tel);
                requestDataMap.put("fileA", "IDCARDF");
                requestDataMap.put("fileB", "IDCARDB");
                requestDataMap.put("fileC", "IDCARDC");
                requestDataMap.put("fileD", "CONTRACT");
// TODO: 2017/6/1 照片顺序
                String path = SharedPreferencesUtils.getString("request_code_take_photo_id_card_photo" + mShopId, "");
                String path2 = SharedPreferencesUtils.getString("request_code_take_photo_bank_card_photo" + mShopId, "");
                String path3 = SharedPreferencesUtils.getString("request_code_take_photo_bank_photo" + mShopId, "");
                String path1 = SharedPreferencesUtils.getString("request_code_take_photo_page_photo" + mShopId, "");

                File fileA = new File(path);
                File fileB = new File(path2);
                File fileC = new File(path1);
                File fileD = new File(path3);


                String requestData = JSON.toJSONString(requestDataMap, false);
                LogUtils.error(requestData);
                Map<String, RequestBody> params = RequestUtils.createPartMap(
                        new RequestParam("serviceCode", "INV_HSY001004"),
                        new RequestParam("requestData", requestData),
                        new RequestParam(HttpConfig.GlobalParam.APP_TYPE, "android"),
                        new RequestParam(HttpConfig.GlobalParam.V, "v1.6"),
                        new RequestParam(HttpConfig.GlobalParam.TIME_STAMP, DateUtils.getCurrentTime()),
                        new RequestParam(HttpConfig.GlobalParam.DEVICE_ID, DeviceUtils.getDeviceId() + ""),
                        new RequestParam("fileA", fileA),
                        new RequestParam("fileB", fileB),
                        new RequestParam("fileC", fileC),
                        new RequestParam("fileD", fileD)
                );
                Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
                final OkHttpClient.Builder builder = new OkHttpClient.Builder();
                retrofitBuilder.client(builder.build())
                        .baseUrl(HttpConfig.BASE_URL) //这里的baseUrl不用设置
                        .addConverterFactory(FastJsonConverterFactory.create())
                        .build()
                        .create(FileApi.class).uploadFileAndForm(params).enqueue(new NetCallBack<String>() {
                    @Override
                    protected void onSuccess(Call<String> call, Response<String> response) {
                        Bundle bundle = new Bundle();
                        bundle.putLong("report_account_id", mUserId);
                        bundle.putLong("report_shop_id", mShopId);
                        bundle.putBoolean("isPublic", mIsPublic);
                        ActivityUtils.startActivityAndFinish(IdentificationShopStep3Activity.this, IdentificationShopStep4Activity.class, bundle);
                    }

                    @Override
                    protected boolean isNullNeedCallback() {
                        return true;
                    }

                    @Override
                    protected void hiddenProgress() {
                        hideLodingDialog();
                    }
                });
                break;
            case R.id.iv_activity_identification_shop_step3_id_card:
                try {
                    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!canEdit) {
                    return;
                }
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(0);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }
                break;
            case R.id.iv_activity_identification_shop_step3_bank_card:
                try {
                    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!canEdit) {
                    return;
                }
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(1);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;

            case R.id.iv_activity_identification_shop_step3_page_new:
                try {
                    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!canEdit) {
                    return;
                }
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(2);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
            case R.id.iv_activity_identification_shop_step3_page://新增
                try {
                    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!canEdit) {
                    return;
                }
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(3);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
        }
    }

    private void takePicture(int requestCode) {
        String path = null;
        switch (requestCode) {
            case 0:
                path = TAKE_PHOTO_PATH_ID_CARD;
                DialogUtils.createPopwindow(IdentificationShopStep3Activity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_ID_CARD);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                            startActivityForResult(intent, 0);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, 4);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 1:
                path = TAKE_PHOTO_PATH_BANK_CARD;
                DialogUtils.createPopwindow(IdentificationShopStep3Activity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_BANK_CARD);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                            startActivityForResult(intent, 1);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, 5);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 3:
                path = TAKE_PHOTO_PATH_CARD;
                DialogUtils.createPopwindow(IdentificationShopStep3Activity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_CARD);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                            startActivityForResult(intent, 2);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, 6);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 2:
                path = TAKE_PHOTO_PATH_PAGE;
                DialogUtils.createPopwindow(IdentificationShopStep3Activity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_PAGE);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                            startActivityForResult(intent, 3);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, 7);
                    }
                }).showAtBottom(mTitleBarView);
                break;


        }

//        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//        File file = new File(Environment.getExternalStorageDirectory(), path);
//
//        if (!file.getParentFile().exists()) {
//            file.getParentFile().mkdirs();
//        }
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//        startActivityForResult(intent, requestCode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String filePath = null;
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 0://法人身份证正面
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_ID_CARD;
                    showLoadingDialog();
                    SharedPreferencesUtils.put("request_code_take_photo_id_card_photo" + mShopId, filePath);
                    new CompressPhotoThread(mHandler, filePath, 0).start();
                    break;
                case 1://法人身份证反面
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_BANK_CARD;
                    showLoadingDialog();
                    SharedPreferencesUtils.put("request_code_take_photo_bank_card_photo" + mShopId, filePath);
                    new CompressPhotoThread(mHandler, filePath, 1).start();
                    break;
                case 2://银行卡证明照
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_CARD;
                    showLoadingDialog();
                    SharedPreferencesUtils.put("request_code_take_photo_bank_photo" + mShopId, filePath);
                    new CompressPhotoThread(mHandler, filePath, 2).start();
                    break;
                case 3://合同照
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_PAGE;
                    showLoadingDialog();
                    SharedPreferencesUtils.put("request_code_take_photo_page_photo" + mShopId, filePath);
                    new CompressPhotoThread(mHandler, filePath, 3).start();
                    break;
                case 4:////法人身份证正面
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();
                    new CompressPhotoThread(mHandler, picturePath, 4).start();
                    SharedPreferencesUtils.put("request_code_take_photo_id_card_photo" + mShopId, picturePath);
                    showLoadingDialog();
                    break;
                case 5:
                    Uri selectedImage1 = data.getData();
                    String[] filePathColumn1 = {MediaStore.Images.Media.DATA};
                    Cursor cursor1 = getContentResolver().query(selectedImage1,
                            filePathColumn1, null, null, null);
                    cursor1.moveToFirst();
                    int columnIndex1 = cursor1.getColumnIndex(filePathColumn1[0]);
                    String picturePath1 = cursor1.getString(columnIndex1);
                    cursor1.close();
                    new CompressPhotoThread(mHandler, picturePath1, 5).start();
                    SharedPreferencesUtils.put("request_code_take_photo_bank_card_photo" + mShopId, picturePath1);
                    showLoadingDialog();
                    break;
                case 6:
                    Uri selectedImage2 = data.getData();
                    String[] filePathColumn2 = {MediaStore.Images.Media.DATA};
                    Cursor cursor2 = getContentResolver().query(selectedImage2,
                            filePathColumn2, null, null, null);
                    cursor2.moveToFirst();
                    int columnIndex2 = cursor2.getColumnIndex(filePathColumn2[0]);
                    String picturePath2 = cursor2.getString(columnIndex2);
                    cursor2.close();
                    new CompressPhotoThread(mHandler, picturePath2, 6).start();
                    SharedPreferencesUtils.put("request_code_take_photo_bank_photo" + mShopId, picturePath2);
                    showLoadingDialog();
                    break;
                case 7:
                    Uri selectedImage3 = data.getData();
                    String[] filePathColumn3 = {MediaStore.Images.Media.DATA};
                    Cursor cursor3 = getContentResolver().query(selectedImage3,
                            filePathColumn3, null, null, null);
                    cursor3.moveToFirst();
                    int columnIndex3 = cursor3.getColumnIndex(filePathColumn3[0]);
                    String picturePath3 = cursor3.getString(columnIndex3);
                    cursor3.close();
                    new CompressPhotoThread(mHandler, picturePath3, 7).start();
                    SharedPreferencesUtils.put("request_code_take_photo_page_photo" + mShopId, picturePath3);
                    showLoadingDialog();
                    break;
            }
        }
    }


    @Override
    protected void handleMessage(BaseActivity context, Message msg) {
        switch (msg.what) {
            case 200: //图片
                int type = (int) msg.obj;
                String path = "";
                ImageView distView = null;
                switch (type) {
                    case 0:
                        photo1 = true;
                        path = TAKE_PHOTO_PATH_ID_CARD;
                        distView = mIdCardView;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 1:
                        photo2 = true;
                        path = TAKE_PHOTO_PATH_BANK_CARD;
                        distView = mBankCardView;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 2:
                        photo3 = true;
                        path = TAKE_PHOTO_PATH_CARD;
                        distView = mPageView;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 3:
                        photo4 = true;
                        path = TAKE_PHOTO_PATH_PAGE;
                        distView = mBankCardViewNew;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;

                    case 4:
                        photo1 = true;
                        distView = mIdCardView;
                        Glide.with(this)//
                                .load(SharedPreferencesUtils.getString("request_code_take_photo_id_card_photo" + mShopId, ""))//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 5:
                        photo2 = true;
                        distView = mBankCardView;
                        Glide.with(this)//
                                .load(SharedPreferencesUtils.getString("request_code_take_photo_bank_card_photo" + mShopId, ""))//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 6:
                        photo3 = true;
                        distView = mPageView;
                        Glide.with(this)//
                                .load(SharedPreferencesUtils.getString("request_code_take_photo_bank_photo" + mShopId, ""))//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                    case 7:
                        photo4 = true;
                        distView = mBankCardViewNew;
                        Glide.with(this)//
                                .load(SharedPreferencesUtils.getString("request_code_take_photo_page_photo" + mShopId, ""))//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        break;
                }

//                Glide.with(this)//
//                        .load(Environment.getExternalStorageDirectory() + "/" + path)//
//                        .skipMemoryCache(true)//
//                        .diskCacheStrategy(DiskCacheStrategy.NONE)
//                        .into(distView);
//
//                distView.setTag(path);
                hideLodingDialog();
                break;
        }
    }
}
